<template>
  <a-card style="width: 100%">
    <p>考点信息查询网址：<a @click="pageTo">http://gs2.zzu.edu.cn/srch/kdgz/ksddcx.html</a></p>

    <a-form :form="form" layout="vertical">
      <a-row :gutter="48">
        <a-col :span="4">
          <a-form-item
            label="考点信息查询时间设置"
          >
            <a-range-picker v-decorator="[
              'kdxxcssj',
              {
                rules: [{ required: true, message: '设置考点信息查询时间!' }],
              }
            ]"/>
          </a-form-item>
        </a-col>
        <a-col :span="12" style="bottom: -28px">
          <a-button style="margin-left: 125px;" type="primary" @click="handleSave">保存</a-button>
        </a-col>
      </a-row>
      <a-row :gutter="48">
        <a-col :span="4">
          <a-form-item
            label="考点信息查询年度设置"
          >
            <a-input v-decorator="[
              'zsnd',
              {
                rules: [{ required: true, message: '设置考点信息查询年度!' }],
              }
            ]"/>
          </a-form-item>
        </a-col>
        <a-col :span="14" style="bottom: -28px">
          <a-button style="margin-left: 125px;" type="primary" @click="saveYear">保存</a-button>
        </a-col>
      </a-row>
    </a-form>
  </a-card>
</template>
<script>
  import moment from 'moment'
  import {mapState} from 'vuex'
  import ACol from "ant-design-vue/es/grid/Col";

  export default {
    name: 'examPlanConfig',
    components: {ACol},
    data() {
      return {}
    },
    computed: {
      ...mapState({
        systemInfo: state => state.app.systemInfo
      })
    },
    beforeCreate() {
      this.form = this.$form.createForm(this)
    },
    created() {
      let params = {}
      this.$api.examPlan.getConfig(params).then(res => {
        this.form.setFieldsValue({zsnd: res.data.xn})
        this.$nextTick(() => {
          this.form.setFieldsValue({kdxxcssj: [new moment(res.data.timeConfig.qssj), new moment(res.data.timeConfig.jssj)]})
        })


      })
    },
    methods: {
      pageTo() {
        window.open('http://gs2.zzu.edu.cn/srch/kdgz/ksddcx.html')
      },
      // 保存操作
      handleSave() {
        this.form.validateFields((err, values) => {
          if (err) {
            return
          }
          let params = {
            qssj: values.kdxxcssj[0].format('YYYY-MM-DD') + ' 00:00:00',
            jssj: values.kdxxcssj[1].format('YYYY-MM-DD') + ' 23:59:59'
          }
          this.$api.examPlan.setTime(params).then(res => {
            this.$message.success(res.msg)
          })
        })
      },
      saveYear() {
        this.form.validateFields((err, values) => {
          if (err) {
            return
          }
          let params = {xn: values.zsnd}
          this.$api.examPlan.setXn(params).then(res => {
            this.$message.success(res.msg)
          })
        })
      }
    }
  }
</script>
